import type { TreeNodeData } from 'element-plus';
import { request } from '../../request';

// get list by page
export function fetchGetPermByPage(params: Api.Common.CommonSearchParams) {
  return request<Api.System.Perm.PermInfoQueryRecord>({
    url: '/rbac/perm_info/listByPage',
    method: 'post',
    data: params
  });
}

// delete by id
export function fetchDeletePermById(id: CommonType.IdType) {
  return request({
    url: '/rbac/perm_info/deleteById',
    method: 'post',
    params: {
      id
    }
  });
}

// delete batch by ids
export function fetchDeletePermBatchByIds(ids: CommonType.IdType[]) {
  return request({
    url: '/rbac/perm_info/deleteBatchByIds',
    method: 'post',
    data: ids
  });
}

// get permission tree data
export function fetchGetPermTree() {
  return request<TreeNodeData[]>({
    url: '/rbac/perm_info/getPermTree',
    method: 'get'
  });
}

// save model
export function fetchPermSave(model: Api.System.Perm.PermInfoFormModel) {
  return request({
    url: '/rbac/perm_info/save',
    method: 'post',
    data: model
  });
}

// get perm level text 获取 权限层级文本
export function fetchGetPermTextByIds(ids: CommonType.IdType[]) {
  return request<string>({
    url: '/rbac/perm_info/getPermTextByIds',
    method: 'post',
    data: ids
  });
}
